<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>用户注册</title>
    <!--CSS-->
    <link rel="stylesheet" type="text/css"
          href="static/js/third-js/extjs66/theme-neptune/resources/theme-neptune-all.css"/>
    <!--js-->
    <script type="text/javascript" src="static/js/third-js/extjs66/ext-all.js"></script>
    <script type="text/javascript" src="static/js/public/variable.js"></script>
    <script type="text/javascript" src="static/js/public/method.js"></script>
    <script type="text/javascript">
        Ext.onReady(function () {
            var registerForm = Ext.create("Ext.form.Panel", {
                title: '用户注册',
                width: 400,
                referenceHolder: true,
                defaultButton: 'registerButton',
                bodyPadding: 10,
                defaultType: 'textfield',
                defaults: {
                    anchor: '100%',
                    labelWidth: 70,
                    labelAlign: "right"
                },
                items: [{
                    allowBlank: false,
                    fieldLabel: '用户名',
                    name: 'username',
                    maxLength: 11,
                    emptyText: '用户名长度不能超过11'
                }, {
                    allowBlank: false,
                    fieldLabel: '姓名',
                    name: 'realName',
                    maxLength: 6,
                    emptyText: '姓名长度不能超过6'
                }, {
                    allowBlank: false,
                    fieldLabel: '密码',
                    name: 'password1',
                    emptyText: '密码长度不能超过20',
                    maxLength: 20,
                    inputType: 'password'
                }, {
                    allowBlank: false,
                    fieldLabel: '再输入密码',
                    name: 'password2',
                    maxLength: 20,
                    emptyText: '密码',
                    inputType: 'password'
                }],
                buttons: [{
                    text: '注册',
                    reference: 'registerButton',
                    handler: function () {
                        if (!registerForm.getForm().isValid())
                            Ext.Msg.alert('错误', '表单信息不符合要求！');
                        else if (registerForm.getForm().findField('password1').getValue() != registerForm.getForm().findField('password2').getValue())
                            Ext.Msg.alert('错误', '两次密码输入不一致！');
                        else {
                            Ext.Ajax.request({
                                url: '/' + authServiceName + '/register',
                                method: 'post',
                                params: {
                                    id: getUuid(),
                                    userName: registerForm.getForm().findField('username').getValue(),
                                    realName: registerForm.getForm().findField('realName').getValue(),
                                    password: registerForm.getForm().findField('password2').getValue()
                                },
                                success: function (response, opts) {
                                    if (response.responseText == 0)
                                        Ext.Msg.alert('错误', '用户名已存在！');
                                    else if (response.responseText == 1) {
                                        Ext.Msg.alert('成功', '注册成功！');
                                        document.location.href = '/' + webServiceName + '/training';
                                    }
                                },
                                failure: function (response, opts) {
                                    console.log('server-side failure with status code ' + response.status);
                                }
                            });
                        }
                    }
                }]
            });
            Ext.create('Ext.window.Window', {
                header: false,
                layout: 'fit',
                items: [registerForm]
            }).show();
        });
    </script>
</head>
<body>
</body>
</html>